<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>测试支付</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="/lobsteruiframe/weui/css/weui.css" />
    <link rel="stylesheet" href="/lobsteruiframe/weui/css/weuix.css" />
    <script src="/lobsteruiframe/weui/js/zepto.min.js"></script>
    <script src="/lobsteruiframe/weui/js/zepto.weui.js"></script>
    <script src="/lobsteruiframe/weui/js/swipe.js"></script>
    <script src="/lobsteruiframe/weui/js/macy.js"></script>
    <script src="/jslib/lobster.js"></script>
    <script src="/jslib/template-web.js"></script>
</head>


<body>
    <div class="" id="s1">
        <div>测试数据</div>
        <code style="text-algin:left">
            <pre>
{
SubMchId:'20220505085609644323',//
BusinessOrderNo:'123',
OrderType:1,//业务类型 1预约挂号 2自助缴费
PayType:1,//默认1 微信支付
PayScene:1,//1 h5 2小程序 3app
Price:4,单位分
Body:'预约挂号',//商品描述
Memo:'备注'//可以不填
}
            </pre>
        </code>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:;" id="topay" class="weui-btn weui-btn_primary">下单</a>
            </p>
        </div>
        <div>退款测试数据</div>
        <div>
            {
                SubMchId: '20220505085609644323',
                BusinessOrderNo: "0",
                BusinessRefundNo: self.generateTimeReqestNumber(),
                PayType: 1,//默认1 微信支付
                PayScene:1,//1 h5 2小程序 3app
                RefundRealFee: 1, //单位分
                RefundDesc: '预约挂号退款',//商品描述 
            }
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:;" id="refund" class="weui-btn weui-btn_primary">退款</a>

            </p>
        </div>
        <div>关闭订单测试数据</div>
        <div>
            { 
                BusinessOrderNo: "20220510110150414919",
            }
        </div>
        <div class="weui-msg__opr-area">
            <p class="weui-btn-area">
                <a href="javascript:;" id="close" class="weui-btn weui-btn_primary">关闭订单</a>

            </p>
        </div>
    </div>
</body>
<script>
    var controller = {
        data: {

        },
        //初始化页面
        initpage: function () {
            this.initevent();
        },
        initevent: function () {
            var self = this;
            $("#topay").click(function () {
                lobsterh5.CALLOUTSERVICE("pay.pay.preorder", {
                    SubMchId: '20220505085609644323',
                    BusinessOrderNo: self.generateTimeReqestNumber(),
                    OrderType:1,//业务类型 1预约挂号 2自助缴费
                    PayType: 1,//默认1 微信支付
                    PayScene:1,//1 h5 2小程序 3app
                    Price: 4, //单位分
                    Body: '预约挂号',//商品描述
                    Memo: '备注'//可以不填
                }).then(res => {
                    location.href = res.payredirecturl;
                }).catch(res => {
                    $.toast(res.msg, 'forbidden');
                });
            })
            $("#refund").click(function () {
                lobsterh5.POSTAPI("tsfront.refund", {
                    SubMchId: '20220505085609644323',
                    BusinessOrderNo: "67",
                    BusinessRefundNo: self.generateTimeReqestNumber(),
                    PayType: 1,//默认1 微信支付
                    RefundRealFee: 1, //单位分
                    RefundDesc: '预约挂号退款',//商品描述 
                }).then(res => {
                    alert('退款成功');
                }).catch(res => {
                    $.toast(res.msg, 'forbidden');
                });
            })
            $("#close").click(function () {
                lobsterh5.CALLOUTSERVICE("pay.pay.closeorder", {
                    SubMchId: '20220505085609644323', 
                    BusinessOrderNo: "20220510110150414919",
                }).then(res => {
                    alert("关闭成功");
                }).catch(res => {
                    $.toast(res.msg, 'forbidden');
                });
            })
        },
        generateTimeReqestNumber: function () {
            var self = this;
            var date = new Date();
            return date.getFullYear().toString() + self.pad2(date.getMonth() + 1) + self.pad2(date.getDate()) + self.pad2(date.getHours()) + self.pad2(date.getMinutes()) + self.pad2(date.getSeconds()) + Math.random().toFixed(6).slice(-6);
        },

        pad2: function (n) { return n < 10 ? '0' + n : n + '' },
    }
    // $(function () {
    //     controller.initpage();
    // })

    lobsterh5.main({
        data: {},
        pageload() {
            controller.initpage();
        }
    })
</script>

</html>